package lijun;

public class Person {
    private String name;
    protected String sex;
    int age;

    public Person() {
        this.name = "";
        this.sex = "";
        this.age = 0;
    }

    public Person(String name, String sex, int age) throws Exception {
        this.name = name;
        this.sex = sex;
        this.age = age;
        if (!(sex.equals("男")||sex.equals("女"))){
            throw new Exception("性别只能为男女");
        }
        if (age>130 || age<0){
            throw new Exception("年龄要0-130之间");
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }
}
